<template>
	<view class="container">
	</view>
</template>

<script>
	//其他小程序跳转到此小程序后浏览页面，当返回时，自己关闭此小程序
	import common from "../../utils/common.js"
	var app = getApp();
	var pageOpt = {};

	export default {
		data() {
			return {};
		},

		onShow: function() {
			//如果已经显示过web-view页了，则执行后退操作，否则就跳到web-view页
			if (!app.webShowed) {
				if (!pageOpt.redirect) {
					wx.navigateBackMiniProgram();
					return false;
				}

				if (pageOpt.redirect == 'webview') {
					if (!pageOpt.webview_title) {
						pageOpt.webview_title = encodeURIComponent('打开页面');
					}

					common.getTxtKey(pageOpt.webview_title).then(key => {
						wx.navigateTo({
							url: '/pages/webview/webview?webview_url=' + pageOpt.webview_url + '&webview_title=' + key
						});
					}, () => {});
				} else if (pageOpt.redirect == 'page') {
					wx.navigateTo({
						url: decodeURIComponent(pageOpt.page)
					});
				}

				app.webShowed = true;
			} else {
				app.webShowed = false;
				wx.navigateBackMiniProgram();
			}
		},
		onLoad: function(opt) {
			pageOpt = opt;
			app.webShowed = false;
			common.getTxtKey('跳转中').then(key => {
				wx.setNavigationBarTitle({
					title: key
				});
			}, () => {});
		},
		components: {},
		props: {},
		methods: {
			setData: function(obj) {
				let that = this;
				let keys = [];
				let val, data;
				Object.keys(obj).forEach(function(key) {
					keys = key.split('.');
					val = obj[key];
					data = that.$data;
					keys.forEach(function(key2, index) {
						if (index + 1 == keys.length) {
							that.$set(data, key2, val);
						} else {
							if (!data[key2]) {
								that.$set(data, key2, {});
							}
						}

						data = data[key2];
					});
				});
			}
		}
	};
</script>
<style>
	/* pages/index/location.css */
</style>
